package web;


import spring.cloud.tasks.client.Client;
import spring.cloud.tasks.client.item_task_processor.Task;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

public class scheduleStrategyDeal {
    public static void main(String[] args) {
        HttpServletRequest request = null;
        String action = request.getParameter("action");
        String result = "";
        boolean isRefreshParent = false;
        Task taskScheduleInfo = new Task();
        taskScheduleInfo.setTaskId(request
                .getParameter("id"));
        try {
            if (action.equalsIgnoreCase("createTask")
                    || action.equalsIgnoreCase("editScheduleStrategy")) {

                taskScheduleInfo.setTaskId(request.getParameter("taskId"));
                taskScheduleInfo.setTaskParameter(request.getParameter("taskParameter"));
                //

                taskScheduleInfo.setTotalProcessorCount(request
                        .getParameter("totalProcessorCount") == null ? 0 : Integer
                        .parseInt(request.getParameter("totalProcessorCount")));
                taskScheduleInfo.setThreadCountPerTaskProcessor(10);
                //
                ArrayList<String> ipList = new ArrayList<String>();
                ipList.add("胡定梅");
                taskScheduleInfo.setIpList(ipList);
                if (action.equalsIgnoreCase("createTask")) {
                    Client.getZooKeeperItemTaskDataManager().createTask(taskScheduleInfo);
                    isRefreshParent = true;
                } else if (action.equalsIgnoreCase("editScheduleStrategy")) {
                    Client.getZooKeeperItemTaskDataManager().updateTask(taskScheduleInfo);
                    isRefreshParent = true;
                }
            } else if (action.equalsIgnoreCase("deleteScheduleStrategy")) {
                Client.getZooKeeperItemTaskDataManager()
                        .cleanTask(
                                taskScheduleInfo.getTaskId());
                isRefreshParent = true;
            } else if (action.equalsIgnoreCase("pauseTask")) {
                Client.getZooKeeperItemTaskDataManager().pauseTask(
                        taskScheduleInfo.getTaskId());
                isRefreshParent = true;
            } else if (action.equalsIgnoreCase("runOrRecoverTask")) {
                Client.getZooKeeperItemTaskDataManager().runOrRecoverTask(
                        taskScheduleInfo.getTaskId());
                isRefreshParent = true;
            } else {
                throw new Exception("��֧�ֵĲ�����" + action);
            }
        } catch (Throwable e) {
            e.printStackTrace();
            result = "ERROR:" + e.getMessage();
            isRefreshParent = false;
        }
    }
}